//
//  DKDebug.h
//  ZhangAo
//
//  Created by 张奥 on 14-9-11.
//  Copyright (c) 2014年 DKHS. All rights reserved.
//

#ifndef DKDebug_h
#define DKDebug_h

#import <Foundation/Foundation.h>

/**
 * Log宏
 */
#ifdef DEBUG
    #define DKLog(xx, ...)      NSLog(@"%s(%d): \n\n" xx "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
    #define DKLog(xx, ...)      ((void)0)
#endif

/**
 * 条件Log宏
 */
#ifdef DEBUG
    #define DKConditionLog(condition, xx, ...) { if ((condition)) { \
                                                        DKLog(xx, ##__VA_ARGS__); \
                                                    } \
                                                } ((void)0)
#else
    #define DKConditionLog(condition, xx, ...) ((void)0)
#endif // #ifdef DEBUG

/**
 * Log in dealloc 方法
 */
#ifdef DEBUG
    #define LOG_CURRENT_OBJECT_IS_DEALLOCATED()           DKLog(@"%@ is deallocated.", NSStringFromClass(self.class))
#else
    #define LOG_CURRENT_OBJECT_IS_DEALLOCATED()           ((void)0)
#endif

/**
 * 断言宏
 */
#ifdef DEBUG

	#ifdef __cplusplus
		extern "C"{
	#endif
			void __kc_assert(const char *filename,NSString *extra,int linenumber,const char * exp);
	#ifdef __cplusplus
		}
	#endif

	#if TARGET_IPHONE_SIMULATOR

		#ifdef __cplusplus
			extern "C"{
		#endif
				int IsInDebugger(void);
		#ifdef __cplusplus
			}
		#endif
		// We leave the __asm__ in this macro so that when a break occurs, we don't have to step out of
		// a "breakInDebugger" function.
		#define DKAssert(xx) { if (!(xx)) { DKLog(@"DKAssert failed: %s", #xx); \
								if (IsInDebugger()) { __asm__("int $3\n" : : ); }; } \
								} ((void)0)
		#define DKAssertWithExtra(xx,extra) DKAssert(xx)
	#else
		#define DKAssert(xx) { if (!(xx)) { DKLog(@"DKAssert failed: %s", #xx); __kc_assert(__FILE__,NULL, __LINE__, #xx);} } ((void)0)
		#define DKAssertWithExtra(xx,extra) { if (!(xx)) { DKLog(@"DKAssert failed: %s", #xx); __kc_assert(__FILE__,extra, __LINE__, #xx);} } ((void)0)
	#endif // #if TARGET_IPHONE_SIMULATOR
#else
	#define DKAssert(xx) ((void)0)
	#define DKAssertWithExtra(xx,extra)	((void)0)
#endif // #ifdef DEBUG




#endif // DKDebug_h
